package com.springboot.controller.tool;

import com.springboot.returndata.dto.tool.CardMessageDto;
import com.springboot.service.tool.ToolService;
import com.springboot.util.http.ResponseBuilder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Classname CardController
 * @Description 证件工具类
 * @Version 1.0.0
 * @Date 2024/4/11 17:43
 * @Created by zyj
 */
@Controller
@RequestMapping("/card")
@Slf4j
@Tag(name = "证件工具")
public class CardController {

    @Resource
    private ToolService toolService;

    @PostMapping(value = "/createIdcardFront")
    @Operation(description = "生成身份证正面")
    public ResponseEntity<byte[]> createIdcardFront(@RequestBody CardMessageDto cardMessage){
        try {
            return ResponseBuilder.downFile(String.valueOf(System.currentTimeMillis()), toolService.createIdCardFront(cardMessage), "jpg");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @PostMapping(value = "/createIdcardBack")
    @Operation(description = "生成身份证背面")
    public ResponseEntity<byte[]> createIdcardBack(@RequestBody CardMessageDto cardMessage){
        try {
            return ResponseBuilder.downFile(String.valueOf(System.currentTimeMillis()), toolService.createIdCardBack(cardMessage), "jpg");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
